// pages/ai/creationComplete/index.js
Page({
  /**
   * 页面的初始数据
   */
  data: {
    currentImg: '',
    activeIndex: 0,
    imgList: [],
    touchS: [0, 0],
    touchE: [0, 0],
    btnHidden:false,
    createtitle:'',
    spacetype:''
  },
  // 触摸开始
  touchStart(e) {
    let sx = e.touches[0].pageX
    let sy = e.touches[0].pageY
    this.setData({
      touchS: [sx, sy]
    })
  },
  // 滑动
  touchMove(e) {
    let sx = e.touches[0].pageX;
    let sy = e.touches[0].pageY;
    this.setData({
      touchE: [sx, sy]
    })
  },
  // 滑动结束
  touchEnd(e) {
    let start = this.data.touchS
    let end = this.data.touchE
    // console.log(start)
    // console.log(end)
    if (start[0] < end[0] - 50) {
      console.log('向右滑')
    } else if (start[0] > end[0] + 50) {
      console.log('向左滑')
    } else {
      console.log('向上或向下滑动')
    }
  },
  // 选中图片
  selectedImg(e) {
    // console.log('index',e.currentTarget.dataset.index);
    this.setData({
      currentImg: e.currentTarget.dataset.value,
      activeIndex: e.currentTarget.dataset.index
    })
  },
  // 跳转页面
  toPage(e) {
    if (this.data.currentImg) wx.setStorageSync('shareImg', this.data.currentImg)
    if (e.currentTarget.dataset.path === "/pages/ai/creativeHall/index") {
      wx.removeStorageSync('styleStr')
      wx.redirectTo({
        url: `${e.currentTarget.dataset.path}?type=2&createtitle=${this.data.createtitle}&spacetype=${this.data.spacetype}`,
      })
    } else {
      wx.navigateTo({
        url: `${e.currentTarget.dataset.path}?type=2`,
      })
    }
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
    if(options){
      this.setData({
        createtitle:options.createtitle,
        spacetype:options.spacetype
      })
    }
    if(options?.isHistory) this.setData({
      btnHidden:true
    })
    if (wx.getStorageSync('shareImgList')) {
      this.setData({
        imgList: wx.getStorageSync('shareImgList').imgList
      })
      if (this.data.imgList.length) {
        this.setData({
          currentImg: this.data.imgList[0]
        })
      }
    }
  }
})